﻿

$(function () {
    $("#btnaccpay").live("click", function () {
        if ($("#divaccpay").is(":hidden")) {
            $("#divaccpay").stop().show('fast');
            $("#btnaccpay").html('－');
        } else {
            $("#divaccpay").stop().hide('fast');
            $("#btnaccpay").html('＋'); 
            $('#txtUserPaidAmt').val('0.00');
            $('#txtTradPws').val('');
            StaticPayAmt();
        }
    });
    $("#txtUserPaidAmt").keyup(function () {
        if (!$(this).val()) { $(this).val('0'); }
        if (isNaN($(this).val())) { $(this).val('0'); }
        if ($(this).val()) {
            if (parseFloat($(this).val()) > parseFloat($("#spnUserAmt").html())) {
                $(this).val($("#spnUserAmt").html());
            }
            if (parseFloat($(this).val()) > parseFloat($('#emPayAMt').html())) {
                $(this).val($('#emPayAMt').html());
            }
            $("#spnUserPaidamt").html(parseFloat($(this).val()).toFixed(2));
            StaticPayAmt();
        }
    });
    $("#J_authSubmit").live("click", function () {
        doConfirmPay();
    });

});

function StaticPayAmt() {
    $("#spnOnlineAmt").html((parseFloat($("#emPayAMt").html()) - parseFloat($("#spnUserPaidamt").html())).toFixed(2));
};

function doUpateAmt() {
    var loadi = layer.load('正在刷新中…');
    try {
        function closeload() { layer.close(loadi); }
        var _jsParam = new jsonRow();
        _jsParam.AddCell("ACTION", "doUpateAmt");
        _jsParam.AddCell("ID", $("#orderId").val());

        ajaxComm(_jsParam, null, closeload);
    }
    catch (err) {
        layer.close(loadi);
    }
};
function doConfirmPay() {
    var loadi = layer.load('正在付款中…');
    try {
        function closeload() { layer.close(loadi); }
        var _jsParam = new jsonRow();
        _jsParam.AddCell("ACTION", "doConfirmPay");
        _jsParam.AddCell("ID", $("#orderId").val());
        _jsParam.AddCell("USER_PAID_AMT", $("#spnUserPaidamt").html());
        _jsParam.AddCell("ONLINE_PAID_AMT", $("#spnOnlineAmt").html());
        _jsParam.AddCell("TRADING_PSW", $("#txtTradPws").val());

        ajaxComm(_jsParam, null, closeload);
    }
    catch (err) {
        layer.close(loadi);
    }
};